<template>
    <van-action-sheet v-model="sheetShow" :actions="actions" @select="select" />
</template>

<script>
    import { mapGetters } from 'vuex';
    export default {
        props: {
            show: {
                type: Boolean,
                required: true
            }
        },
        data() {
            return {
                actions: [
                    { name: '开始获取离线' },
                    { name: '停止获取离线' },
                    { name: '暂停获取离线' },
                    { name: '继续获取离线' },
                    { name: '清除离线数据' }
                ]
            }
        },
        computed: {
            ...mapGetters(['bluetooth','qwBluetooth']),
            sheetShow: {
                get({ show }) { return show },
                set(newVal) {
                    this.$emit('update:show', newVal)
                }
            }
        },
        methods: {
            //面板选项
            select(item) {
                switch (item.name) {
                    case this.actions[0].name: //开始获取离线
                        this.qwBluetooth.startOfflineTransfer()
                        break;
                    case this.actions[1].name: //停止获取离线
                        this.qwBluetooth.stopOfflineTransfer()
                        break;
                    case this.actions[2].name: //暂停获取离线
                        this.qwBluetooth.pauseOfflineTransfer()
                        break;
                    case this.actions[3].name: //继续获取离线
                        this.qwBluetooth.continueOfflineTransfer()
                        break;
                    case this.actions[4].name: //清除获取离线
                        this.$dialog.confirm({
                                title: '提示',
                                message: '确定清除离线数据吗？',
                            })
                            .then(() => {
                                this.qwBluetooth.deleteOfflineData()
                            })
                            .catch(() => {
                                return
                            });
                        break;
                }
                this.$emit('update:show', false)
            }
        }
    }
</script>

<style>

</style>